<template>
  <div>
    <h3>支付成功</h3>
    <p>{{ count }}</p>
    <button @click="this.$router.push({ path: '/' })">返回首页</button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      count: 3, // 初始值为10秒
    };
  },
  mounted() {
    // 启动计时器，每秒更新count值
    this.timer = setInterval( () => {
      if ( this.count > 0 ) {
        this.count--;
      } else {
        clearInterval( this.timer );
        this.$router.push( { path: '/' } ) // 倒计时结束，停止计时器
      }
    }, 1000 );
  },
  beforeDestroy() {
    // 组件销毁时清除计时器
    clearInterval( this.timer );
  },
};
</script>

<style scoped>
div {
  margin: 100px auto;
  width: 600px;
  height: 500px;
  text-align: center;
}

h3 {
  font-size: 70px;
  letter-spacing: 5px;
  font-weight: bold;
  color: rgb(255, 0, 115);
}

p {
  margin: 100px;
  font-size: 80px;
  color: #f8b2c9;
}

button {
  font-size: 30px;
  color: rgb(255, 0, 115);
}

button:hover {
  text-decoration: underline;
}
</style>